Skip to content

wolfSSL_X509_verify_cert: add host check from ctx->param#9952

Open
julek-wolfssl wants to merge 3 commits intowolfSSL:masterfrom
julek-wolfssl:zd/21324
Open

wolfSSL_X509_verify_cert: add host check from ctx->param#9952
julek-wolfssl wants to merge 3 commits intowolfSSL:masterfrom
julek-wolfssl:zd/21324

Conversation

@julek-wolfssl
Copy link
Member

ZD21324

Copilot AI review requested due to automatic review settings March 11, 2026 17:20
@julek-wolfssl julek-wolfssl self-assigned this Mar 11, 2026
@julek-wolfssl julek-wolfssl added the Not For This Release Not for release 5.9.0 label Mar 11, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds OpenSSL-compatible hostname/IP enforcement to wolfSSL_X509_verify_cert() based on values set in WOLFSSL_X509_STORE_CTX->param, and introduces a regression test to ensure hostname mismatches are rejected.

Changes:

  • Enforce hostname (hostName) and IP (ipasc) checks during wolfSSL_X509_verify_cert() when configured via X509_VERIFY_PARAM.
  • Add a regression test that verifies hostname match/mismatch behavior and the resulting error code.
  • Register the new test in the API test declarations.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/x509_str.c Adds hostname/IP enforcement to wolfSSL_X509_verify_cert() when ctx->param is configured.
tests/api/test_x509.c Adds a regression test covering success with no hostname, success with matching SAN DNS, and failure on mismatch.
tests/api/test_x509.h Exposes and registers the new test in the x509 test group.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copilot AI review requested due to automatic review settings March 16, 2026 17:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +302 to +305
ExpectIntNE(wolfSSL_X509_verify_cert(ctx), WOLFSSL_SUCCESS);
ExpectIntEQ(wolfSSL_X509_STORE_CTX_get_error(ctx),
X509_V_ERR_HOSTNAME_MISMATCH);
ExpectIntEQ(wolfSSL_X509_STORE_CTX_get_error_depth(ctx), 0);
Comment on lines +743 to +772
/* Enforce hostname / IP verification from X509_VERIFY_PARAM if set. */
if (ret == WOLFSSL_SUCCESS && ctx->param != NULL) {
if (ctx->param->hostName[0] != '\0') {
if (wolfSSL_X509_check_host(ctx->current_cert,
ctx->param->hostName,
XSTRLEN(ctx->param->hostName),
ctx->param->hostFlags, NULL) != WOLFSSL_SUCCESS) {
#ifndef OPENSSL_COEXIST
ctx->error = X509_V_ERR_HOSTNAME_MISMATCH;
#else
ctx->error = 1; /* Return generic error */
#endif
ctx->error_depth = 0;
ret = WOLFSSL_FAILURE;
}
}
else if (ctx->param->ipasc[0] != '\0') {
if (wolfSSL_X509_check_ip_asc(ctx->current_cert,
ctx->param->ipasc,
ctx->param->hostFlags) != WOLFSSL_SUCCESS) {
#ifndef OPENSSL_COEXIST
ctx->error = X509_V_ERR_IP_ADDRESS_MISMATCH;
#else
ctx->error = 1; /* Return generic error */
#endif
ctx->error_depth = 0;
ret = WOLFSSL_FAILURE;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Not For This Release Not for release 5.9.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants